package cn.slb.im.modules.chat.service.impl;

import cn.slb.im.common.utils.PageUtils;
import cn.slb.im.common.utils.Query;
import cn.slb.im.modules.chat.dto.ChatMessageDTO;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.slb.im.modules.chat.dao.ChatDao;
import cn.slb.im.modules.chat.entity.ChatEntity;
import cn.slb.im.modules.chat.service.ChatService;


@Service("chatService")
public class ChatServiceImpl extends ServiceImpl<ChatDao, ChatEntity> implements ChatService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ChatEntity> page = this.page(
                new Query<ChatEntity>().getPage(params),
                new QueryWrapper<ChatEntity>()
        );

        return new PageUtils(page);
    }

    @Async
    @Override
    public void saveChat(ChatMessageDTO dto) {
        ChatEntity entity = new ChatEntity();
        entity.setFromId(dto.getFromId());
        entity.setToId(dto.getToId());
        entity.setMsg(dto.getMsg());
        this.save(entity);
    }
}
